package com.example.module_patrol.ui

import com.example.module_patrol.http.PatrolApi
import com.example.module_patrol.http.PatrolNetModule
import com.example.module_patrol.model.PatrolEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

class PatrolRepository @Inject constructor() {
    @Inject
    @PatrolNetModule.CommonMainApi
    lateinit var patrolApi: PatrolApi

    /*
   获取巡逻点位列表
    */
    fun getParkingList() = flow {
        emit(patrolApi.getPatrolList())
    }.flowOn(Dispatchers.IO)
    /*
   添加巡逻点位
     */
    fun addPatrol(patrolEntity: PatrolEntity) = flow {
        emit(patrolApi.addPatrol(patrolEntity))
    }.flowOn(Dispatchers.IO)

    /*
    根据点位名称及位置获取巡检点位详情
     */
    fun searchPatrol(location:String,name:String) = flow {
        emit(patrolApi.searchPatrol(location,name))
    }.flowOn(Dispatchers.IO)
    /*
    获取指定状态的巡检点位列表
     */
    fun getPatrolTaskByStatus(status:String) = flow {
        emit(patrolApi.getPatrolTaskByStatus(status))
    }.flowOn(Dispatchers.IO)

    /*
    获取指定id的巡检点位详情
     */
    fun getPatrolById(id:Int) = flow {
        emit(patrolApi.getPatrolById(id))
    }.flowOn(Dispatchers.IO)

    /*
    获取指定时间段的巡检点位列表
     */
    fun getPatrolTaskByDate(startDate:String,end:String) = flow {
        emit(patrolApi.getPatrolTaskByDate(startDate,end))
    }.flowOn(Dispatchers.IO)

}